package metalink.admin;


import java.util.ArrayList;
import java.util.Vector;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import vo.BatchDetailsVo;
import vo.mixed.CourseListVo;
import vo.mixed.DegreeListVo;
import vo.mixed.DepartmentListVo;
import vo.mixed.HostelStudentVo;
import vo.mixed.ProfessorListVo;
import vo.mixed.StudentListVo;

import model.admin.GetBatchListMo;
import model.admin.ModifyBatchDetailsMo;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class GetBatchList extends ActionSupport {
int batch_id;
int degree_id;
String value="";
ArrayList<BatchDetailsVo> batch_list;
ArrayList<CourseListVo> batch_course_list;
ArrayList<DegreeListVo> batch_degree_list;
ArrayList<DepartmentListVo> batch_department_list;
ArrayList<DegreeListVo> add_batch_degree_list = new ArrayList<DegreeListVo>();
ArrayList<StudentListVo> batch_student_list;
ArrayList<ProfessorListVo> batch_professor_list;
HttpSession session;
private int result;

//------------ Pagination --------------//
private int page;
private String morepages;
private Vector noofpages=new Vector();
private int nextpage;
private int currentpage;
private String hasprevpage;
private int prevpage;
private int items;
//private Vector pagelist=new Vector();


public int getBatch_id() {
	return batch_id;
}

public void setBatch_id(int batch_id) {
	this.batch_id = batch_id;
}


	public ArrayList<CourseListVo> getBatch_course_list() {
	return batch_course_list;
}

public void setBatch_course_list(ArrayList<CourseListVo> batch_course_list) {
	this.batch_course_list = batch_course_list;
}

	public ArrayList<BatchDetailsVo> getBatch_list() {
	return batch_list;
}

public void setBatch_list(ArrayList<BatchDetailsVo> batch_list) {
	this.batch_list = batch_list;
}

	public ArrayList<DegreeListVo> getBatch_degree_list() {
	return batch_degree_list;
}

public void setBatch_degree_list(ArrayList<DegreeListVo> batch_degree_list) {
	this.batch_degree_list = batch_degree_list;
}

public ArrayList<DepartmentListVo> getBatch_department_list() {
	return batch_department_list;
}

public void setBatch_department_list(
		ArrayList<DepartmentListVo> batch_department_list) {
	this.batch_department_list = batch_department_list;
}

public ArrayList<StudentListVo> getBatch_student_list() {
	return batch_student_list;
}

public void setBatch_student_list(
		ArrayList<StudentListVo> batch_student_list) {
	this.batch_student_list = batch_student_list;
}

	public ArrayList<ProfessorListVo> getBatch_professor_list() {
	return batch_professor_list;
}

public void setBatch_professor_list(
		ArrayList<ProfessorListVo> batch_professor_list) {
	this.batch_professor_list = batch_professor_list;
}

public String execute() throws Exception {
	ModifyBatchDetailsMo modifymo = new ModifyBatchDetailsMo();
	
	GetBatchListMo BatchListObject= new GetBatchListMo();
	
	if(value.contentEquals("degree")){
		ArrayList<DegreeListVo> pagelist = new ArrayList<DegreeListVo>();
		add_batch_degree_list=BatchListObject.getAddDegreeToBatch(batch_id);
		batch_degree_list=BatchListObject.getBatchDegreeList(batch_id);
		result = batch_degree_list.size();
		
		//---------- Pagination ------------------//
		
				int p=getPage();
		        if(p==0)
		        {
		            setHasprevpage("false");
		        }
		        else
		        {
		            setHasprevpage("true");
		            setPrevpage(p-1);
		        }

		        setCurrentpage(p);

		        int count;
		        count=0;

		        int size=batch_degree_list.size();
		        setItems(size);
		        int pagesinlist=size/15;
		        while(count<=pagesinlist)
		        {
		            noofpages.add(count);
		            count++;
		        }
		        count=0;
		        while(count<15)
		        {

		            if(size>=(p*15)+count+1)
		            {
		                System.out.println(p);
		                pagelist.add(batch_degree_list.get((p*15)+count));
		                System.out.println((p*15)+count);
		                System.out.println("size"+pagelist.size());
		                count++;
		                setMorepages("true");
		                setNextpage(p+1);

		            }
		            else
		            {
		                setMorepages("false");
		                break;
		            }
		        }
	}else if(value.contentEquals("adddegree")){
		ArrayList<DegreeListVo> pagelist = new ArrayList<DegreeListVo>();
		modifymo.addDegreetoBatch(degree_id, batch_id,value);
		batch_degree_list=BatchListObject.getBatchDegreeList(batch_id);
		result = batch_degree_list.size();
		add_batch_degree_list=BatchListObject.getAddBatchDegree(batch_id);
		//---------- Pagination ------------------//
		
		int p=getPage();
        if(p==0)
        {
            setHasprevpage("false");
        }
        else
        {
            setHasprevpage("true");
            setPrevpage(p-1);
        }

        setCurrentpage(p);

        int count;
        count=0;

        int size=batch_degree_list.size();
        setItems(size);
        int pagesinlist=size/15;
        while(count<=pagesinlist)
        {
            noofpages.add(count);
            count++;
        }
        count=0;
        while(count<15)
        {

            if(size>=(p*15)+count+1)
            {
                System.out.println(p);
                pagelist.add(batch_degree_list.get((p*15)+count));
                System.out.println((p*15)+count);
                System.out.println("size"+pagelist.size());
                count++;
                setMorepages("true");
                setNextpage(p+1);

            }
            else
            {
                setMorepages("false");
                break;
            }
        }
	}else if (value.contentEquals("displaycourse")){
		ArrayList<CourseListVo> pagelist = new ArrayList<CourseListVo>();
		batch_course_list= BatchListObject.getBatchCourseList(batch_id, 0);
		result = batch_course_list.size();
		//---------- Pagination ------------------//
		
		int p=getPage();
        if(p==0)
        {
            setHasprevpage("false");
        }
        else
        {
            setHasprevpage("true");
            setPrevpage(p-1);
        }

        setCurrentpage(p);

        int count;
        count=0;

        int size=batch_course_list.size();
        setItems(size);
        int pagesinlist=size/15;
        while(count<=pagesinlist)
        {
            noofpages.add(count);
            count++;
        }
        count=0;
        while(count<15)
        {

            if(size>=(p*15)+count+1)
            {
                System.out.println(p);
                pagelist.add(batch_course_list.get((p*15)+count));
                System.out.println((p*15)+count);
                System.out.println("size"+pagelist.size());
                count++;
                setMorepages("true");
                setNextpage(p+1);

            }
            else
            {
                setMorepages("false");
                break;
            }
        }
	}
	else if (value.contentEquals("deletebatchdegree")){
		ArrayList<DegreeListVo> pagelist = new ArrayList<DegreeListVo>();
		GetBatchListMo mo = new GetBatchListMo();
		mo.deletebatch(batch_id, degree_id, value);
		batch_degree_list=BatchListObject.getBatchDegreeList(batch_id);
		result = batch_degree_list.size();
		add_batch_degree_list=BatchListObject.getAddBatchDegree(batch_id);
		//---------- Pagination ------------------//
		
		int p=getPage();
        if(p==0)
        {
            setHasprevpage("false");
        }
        else
        {
            setHasprevpage("true");
            setPrevpage(p-1);
        }

        setCurrentpage(p);

        int count;
        count=0;

        int size=batch_degree_list.size();
        setItems(size);
        int pagesinlist=size/15;
        while(count<=pagesinlist)
        {
            noofpages.add(count);
            count++;
        }
        count=0;
        while(count<15)
        {

            if(size>=(p*15)+count+1)
            {
                System.out.println(p);
                pagelist.add(batch_degree_list.get((p*15)+count));
                System.out.println((p*15)+count);
                System.out.println("size"+pagelist.size());
                count++;
                setMorepages("true");
                setNextpage(p+1);

            }
            else
            {
                setMorepages("false");
                break;
            }
        }
	}
	else if(value.contentEquals("displaydep")){
		ArrayList<DepartmentListVo> pagelist = new ArrayList<DepartmentListVo>();
		batch_department_list=BatchListObject.getDepartmentList(batch_id, 0, 0);
		result = batch_department_list.size();
		//---------- Pagination ------------------//
		
		int p=getPage();
        if(p==0)
        {
            setHasprevpage("false");
        }
        else
        {
            setHasprevpage("true");
            setPrevpage(p-1);
        }

        setCurrentpage(p);

        int count;
        count=0;

        int size=batch_department_list.size();
        setItems(size);
        int pagesinlist=size/15;
        while(count<=pagesinlist)
        {
            noofpages.add(count);
            count++;
        }
        count=0;
        while(count<15)
        {

            if(size>=(p*15)+count+1)
            {
                System.out.println(p);
                pagelist.add(batch_department_list.get((p*15)+count));
                System.out.println((p*15)+count);
                System.out.println("size"+pagelist.size());
                count++;
                setMorepages("true");
                setNextpage(p+1);

            }
            else
            {
                setMorepages("false");
                break;
            }
        }
	}else if(value.contentEquals("displayprof")){
		ArrayList<ProfessorListVo> pagelist = new ArrayList<ProfessorListVo>();
		batch_professor_list=BatchListObject.getBatchProfessorList(batch_id);
		result = batch_professor_list.size();
		//---------- Pagination ------------------//
		
		int p=getPage();
        if(p==0)
        {
            setHasprevpage("false");
        }
        else
        {
            setHasprevpage("true");
            setPrevpage(p-1);
        }

        setCurrentpage(p);

        int count;
        count=0;

        int size=batch_professor_list.size();
        setItems(size);
        int pagesinlist=size/15;
        while(count<=pagesinlist)
        {
            noofpages.add(count);
            count++;
        }
        count=0;
        while(count<15)
        {

            if(size>=(p*15)+count+1)
            {
                System.out.println(p);
                pagelist.add(batch_professor_list.get((p*15)+count));
                System.out.println((p*15)+count);
                System.out.println("size"+pagelist.size());
                count++;
                setMorepages("true");
                setNextpage(p+1);

            }
            else
            {
                setMorepages("false");
                break;
            }
        }
	}else if(value.contentEquals("displaystu")){
		ArrayList<StudentListVo> pagelist = new ArrayList<StudentListVo>();
		batch_student_list=BatchListObject.getBatchStudentList(batch_id, 0);
		result = batch_student_list.size();
		//---------- Pagination ------------------//
		
		int p=getPage();
        if(p==0)
        {
            setHasprevpage("false");
        }
        else
        {
            setHasprevpage("true");
            setPrevpage(p-1);
        }

        setCurrentpage(p);

        int count;
        count=0;

        int size=batch_student_list.size();
        setItems(size);
        int pagesinlist=size/15;
        while(count<=pagesinlist)
        {
            noofpages.add(count);
            count++;
        }
        count=0;
        while(count<15)
        {

            if(size>=(p*15)+count+1)
            {
                System.out.println(p);
                pagelist.add(batch_student_list.get((p*15)+count));
                System.out.println((p*15)+count);
                System.out.println("size"+pagelist.size());
                count++;
                setMorepages("true");
                setNextpage(p+1);

            }
            else
            {
                setMorepages("false");
                break;
            }
        }
	}
	else{
	setBatch_list(BatchListObject.getBatchList());
	}
	return SUCCESS;
}
/*
	public String execute() throws Exception {
		ArrayList<BatchDetailsVo> pagelist;
		GetBatchListMo BatchListObject= new GetBatchListMo();
		setBatch_list(BatchListObject.getBatchList());
		pagelist = new ArrayList<BatchDetailsVo>();
result = batch_list.size();
		
		//---------- Pagination ------------------//
		
		int p=getPage();
        if(p==0)
        {
            setHasprevpage("false");
        }
        else
        {
            setHasprevpage("true");
            setPrevpage(p-1);
        }

        setCurrentpage(p);

        int count;
        count=0;

        int size=batch_list.size();
        setItems(size);
        int pagesinlist=size/15;
        while(count<=pagesinlist)
        {
            noofpages.add(count);
            count++;
        }
        count=0;
        while(count<15)
        {

            if(size>=(p*15)+count+1)
            {
                System.out.println(p);
                pagelist.add(batch_list.get((p*15)+count));
                System.out.println((p*15)+count);
                System.out.println("size"+pagelist.size());
                count++;
                setMorepages("true");
                setNextpage(p+1);

            }
            else
            {
                setMorepages("false");
                break;
            }
        }
		
		return SUCCESS;
	}

	public String getBatchDepartmentDetails() throws Exception {
		
		GetBatchListMo BatchDepartmentList= new GetBatchListMo();
		setBatch_department_list(BatchDepartmentList.getDepartmentList(batch_id,0));

		ArrayList<DepartmentListVo> pagelist = new ArrayList<DepartmentListVo>();
		session = ServletActionContext.getRequest().getSession();
		session.setAttribute("batch_id", batch_id);
result = BatchDepartmentList.getDepartmentList(batch_id,0).size();
		
		//---------- Pagination ------------------//
		
		int p=getPage();
        if(p==0)
        {
            setHasprevpage("false");
        }
        else
        {
            setHasprevpage("true");
            setPrevpage(p-1);
        }

        setCurrentpage(p);

        int count;
        count=0;

        int size=BatchDepartmentList.getDepartmentList(batch_id,0).size();
        setItems(size);
        int pagesinlist=size/15;
        while(count<=pagesinlist)
        {
            noofpages.add(count);
            count++;
        }
        count=0;
        while(count<15)
        {

            if(size>=(p*15)+count+1)
            {
                System.out.println(p);
                pagelist.add(BatchDepartmentList.getDepartmentList(batch_id,0).get((p*15)+count));
                System.out.println((p*15)+count);
                System.out.println("size"+pagelist.size());
                count++;
                setMorepages("true");
                setNextpage(p+1);

            }
            else
            {
                setMorepages("false");
                break;
            }
        }
		return SUCCESS;
	}

	public String getBatchCourseDetails() throws Exception {
		GetBatchListMo BatchCourseList= new GetBatchListMo();
		setBatch_course_list(BatchCourseList.getBatchCourseList(batch_id,0));
		
		ArrayList<CourseListVo> pagelist = new ArrayList<CourseListVo>();
		session = ServletActionContext.getRequest().getSession();
		session.setAttribute("batch_id", batch_id);
result = BatchCourseList.getBatchCourseList(batch_id,0).size();
		
		//---------- Pagination ------------------//
		
		int p=getPage();
        if(p==0)
        {
            setHasprevpage("false");
        }
        else
        {
            setHasprevpage("true");
            setPrevpage(p-1);
        }

        setCurrentpage(p);

        int count;
        count=0;

        int size=BatchCourseList.getBatchCourseList(batch_id,0).size();
        setItems(size);
        int pagesinlist=size/15;
        while(count<=pagesinlist)
        {
            noofpages.add(count);
            count++;
        }
        count=0;
        while(count<15)
        {

            if(size>=(p*15)+count+1)
            {
                System.out.println(p);
                pagelist.add(BatchCourseList.getBatchCourseList(batch_id,0).get((p*15)+count));
                System.out.println((p*15)+count);
                System.out.println("size"+pagelist.size());
                count++;
                setMorepages("true");
                setNextpage(p+1);

            }
            else
            {
                setMorepages("false");
                break;
            }
        }
		return SUCCESS;
	}

	public String getBatchProfessorDetails() throws Exception {
		GetBatchListMo BatchProfessorList= new GetBatchListMo();
		setBatch_professor_list(BatchProfessorList.getBatchProfessorList(batch_id));

		ArrayList<ProfessorListVo> pagelist = new ArrayList<ProfessorListVo>();
		session = ServletActionContext.getRequest().getSession();
		session.setAttribute("batch_id", batch_id);
result = BatchProfessorList.getBatchProfessorList(batch_id).size();
		
		//---------- Pagination ------------------//
		
		int p=getPage();
        if(p==0)
        {
            setHasprevpage("false");
        }
        else
        {
            setHasprevpage("true");
            setPrevpage(p-1);
        }

        setCurrentpage(p);

        int count;
        count=0;

        int size=BatchProfessorList.getBatchProfessorList(batch_id).size();
        setItems(size);
        int pagesinlist=size/15;
        while(count<=pagesinlist)
        {
            noofpages.add(count);
            count++;
        }
        count=0;
        while(count<15)
        {

            if(size>=(p*15)+count+1)
            {
                System.out.println(p);
                pagelist.add(BatchProfessorList.getBatchProfessorList(batch_id).get((p*15)+count));
                System.out.println((p*15)+count);
                System.out.println("size"+pagelist.size());
                count++;
                setMorepages("true");
                setNextpage(p+1);

            }
            else
            {
                setMorepages("false");
                break;
            }
        }
		
		return SUCCESS;
	}

	public String getBatchStudentDetails() throws Exception {
		GetBatchListMo BatchStudentList= new GetBatchListMo();
		setBatch_student_list(BatchStudentList.getBatchStudentList(batch_id,0));

		ArrayList<StudentListVo> pagelist = new ArrayList<StudentListVo>();
		session = ServletActionContext.getRequest().getSession();
		session.setAttribute("batch_id", batch_id);
result = BatchStudentList.getBatchStudentList(batch_id,0).size();
		
		//---------- Pagination ------------------//
		
		int p=getPage();
        if(p==0)
        {
            setHasprevpage("false");
        }
        else
        {
            setHasprevpage("true");
            setPrevpage(p-1);
        }

        setCurrentpage(p);

        int count;
        count=0;

        int size=BatchStudentList.getBatchStudentList(batch_id,0).size();
        setItems(size);
        int pagesinlist=size/15;
        while(count<=pagesinlist)
        {
            noofpages.add(count);
            count++;
        }
        count=0;
        while(count<15)
        {

            if(size>=(p*15)+count+1)
            {
                System.out.println(p);
                pagelist.add(BatchStudentList.getBatchStudentList(batch_id,0).get((p*15)+count));
                System.out.println((p*15)+count);
                System.out.println("size"+pagelist.size());
                count++;
                setMorepages("true");
                setNextpage(p+1);

            }
            else
            {
                setMorepages("false");
                break;
            }
        }
		
		return SUCCESS;
	}

	public String getBatchDegreeDetails() throws Exception {

		GetBatchListMo BatchDegreeList= new GetBatchListMo();
		setBatch_degree_list(BatchDegreeList.getBatchDegreeList(batch_id));
		
		ArrayList<DegreeListVo> pagelist = new ArrayList<DegreeListVo>();
		session = ServletActionContext.getRequest().getSession();
		session.setAttribute("batch_id", batch_id);
result = BatchDegreeList.getBatchDegreeList(batch_id).size();
		
		//---------- Pagination ------------------//
		
		int p=getPage();
        if(p==0)
        {
            setHasprevpage("false");
        }
        else
        {
            setHasprevpage("true");
            setPrevpage(p-1);
        }

        setCurrentpage(p);

        int count;
        count=0;

        int size=BatchDegreeList.getBatchDegreeList(batch_id).size();
        setItems(size);
        int pagesinlist=size/15;
        while(count<=pagesinlist)
        {
            noofpages.add(count);
            count++;
        }
        count=0;
        while(count<15)
        {

            if(size>=(p*15)+count+1)
            {
                System.out.println(p);
                pagelist.add(BatchDegreeList.getBatchDegreeList(batch_id).get((p*15)+count));
                System.out.println((p*15)+count);
                System.out.println("size"+pagelist.size());
                count++;
                setMorepages("true");
                setNextpage(p+1);

            }
            else
            {
                setMorepages("false");
                break;
            }
        }
		
return SUCCESS;
	}

	
	// to be kept in different file 
	public String editBatchStudentDetails() throws Exception {
		return SUCCESS;
	}

	public String deleteBatchStudentDetails() throws Exception {
		return SUCCESS;
	}

	public String addNewStudent() throws Exception {
		return SUCCESS;
	}
*/
	public int getResult() {
		return result;
	}

	public void setResult(int result) {
		this.result = result;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public String getMorepages() {
		return morepages;
	}

	public void setMorepages(String morepages) {
		this.morepages = morepages;
	}

	public Vector getNoofpages() {
		return noofpages;
	}

	public void setNoofpages(Vector noofpages) {
		this.noofpages = noofpages;
	}

	public int getNextpage() {
		return nextpage;
	}

	public void setNextpage(int nextpage) {
		this.nextpage = nextpage;
	}

	public int getCurrentpage() {
		return currentpage;
	}

	public void setCurrentpage(int currentpage) {
		this.currentpage = currentpage;
	}

	public String getHasprevpage() {
		return hasprevpage;
	}

	public void setHasprevpage(String hasprevpage) {
		this.hasprevpage = hasprevpage;
	}

	public int getPrevpage() {
		return prevpage;
	}

	public void setPrevpage(int prevpage) {
		this.prevpage = prevpage;
	}

	public int getItems() {
		return items;
	}

	public void setItems(int items) {
		this.items = items;
	}
/*
	public ArrayList<BatchDetailsVo> getPagelist() {
		return pagelist;
	}

	public void setPagelist(ArrayList<BatchDetailsVo> pagelist) {
		this.pagelist = pagelist;
	}
*/

	public ArrayList<DegreeListVo> getAdd_batch_degree_list() {
		return add_batch_degree_list;
	}

	public void setAdd_batch_degree_list(
			ArrayList<DegreeListVo> add_batch_degree_list) {
		this.add_batch_degree_list = add_batch_degree_list;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public int getDegree_id() {
		return degree_id;
	}

	public void setDegree_id(int degree_id) {
		this.degree_id = degree_id;
	}
}
